#include <signal.h>
#include "debug_log.h"
#include "vs_world.h"
#include "signals.h"

extern vs_world_t* g_vs_world;

void hook_signals()
{
    signal(SIGINT, on_signal);
    signal(SIGTERM, on_signal);
    signal(SIGABRT, on_signal);
    signal(SIGBREAK, on_signal);
}

void on_signal(int s)
{
	char* err = "UNKNOWN";
	switch (s)
    {
        case SIGINT:
			err = "SIGINT";
			g_vs_world->world_stop = 1;
			break;
        case SIGTERM:
			err = "SIGTERM";
			g_vs_world->world_stop = 1;
			break;
        case SIGABRT:
			err = "SIGABRT";
			g_vs_world->world_stop = 1;
			break;
        case SIGBREAK:
			err = "SIGBREAK";
			g_vs_world->world_stop = 1;
			break;
    }

	dbg_print("Process signal %s",err);

    signal(s, on_signal);
}